package com.example.springboot_vue.controller;


import com.example.springboot_vue.common.CommonDto;
import com.example.springboot_vue.common.PageDto;
import com.example.springboot_vue.entity.Goods;
import com.example.springboot_vue.entity.StorageEntity;
import com.example.springboot_vue.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sgp
 * @since 2024-07-19
 */
@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;


    @GetMapping("/selectAll")
    public CommonDto selectAll(Goods goods){
        CommonDto<PageDto<Goods>> commonDto = new CommonDto<>();
        PageDto<Goods> pageDto = goodsService.selectAll(goods);
        commonDto.setContent(pageDto);
        return commonDto;
    }

    @GetMapping("/del/{id}")
    public CommonDto del(@PathVariable Integer id){
        CommonDto<Goods> commonDto = new CommonDto<>();
        goodsService.removeById(id);
        commonDto.setMessage("删除成功");
        return commonDto;
    }

    @PostMapping("/save")
    public CommonDto save(@RequestBody Goods goods){
        CommonDto<Goods> commonDto = new CommonDto<>();
        goodsService.save(goods);
        commonDto.setMessage("新增成功");
        return commonDto;
    }

    @PostMapping("/update")
    public CommonDto update(@RequestBody Goods goods){
        CommonDto<StorageEntity> commonDto = new CommonDto<>();
        goodsService.updateById(goods);
        commonDto.setMessage("修改成功");
        return commonDto;
    }
}
